package windows;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import bussinesmodel.CAdministrator;

import utilities.CListModel;


public class CAddSupplierPane extends JPanel
{
	
	
	 private javax.swing.JTextField fieldNit;
	    private javax.swing.JTextField fieldSupplier;
	    private javax.swing.JLabel labeNit;
	    private javax.swing.JLabel labeSupplier;
	    private javax.swing.JLabel labelTittle;
	    private javax.swing.JSeparator separadorTitulo;
	    private CAdministrator administrator;
	    private JButton buttonSave;
	    
	    public CAddSupplierPane() 
	    {
	        initComponents();
	    }
	    
	    private void initComponents() {

	        separadorTitulo = new javax.swing.JSeparator();
	        labelTittle = new javax.swing.JLabel();
	        labeSupplier = new javax.swing.JLabel();
	        fieldSupplier = new javax.swing.JTextField();
	        labeNit = new javax.swing.JLabel();
	        fieldNit = new javax.swing.JTextField();
	        buttonSave=new JButton("Guardar");

	        
	        setLayout(null);

	        separadorTitulo.setForeground(new java.awt.Color(0, 0, 0));
	        add(separadorTitulo);
	        separadorTitulo.setBounds(40, 52, 220, 2);

	        labelTittle.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
	        labelTittle.setForeground(new java.awt.Color(0, 0, 102));
	        labelTittle.setText("Ingrese el nuevo Proveedor");
	        add(labelTittle);
	        labelTittle.setBounds(50, 30, 210, 17);

	        labeSupplier.setText("Nombre Proveedor:");
	        add(labeSupplier);
	        labeSupplier.setBounds(40, 90, 120, 14);

	        fieldSupplier.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
					char c = e.getKeyChar();
					if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
					} else {
						String texto = String.valueOf(c);
						e.consume();
						fieldSupplier.setText(fieldSupplier.getText()
								+ texto.toUpperCase());
					}
				}
			});
	        
	        
	        add(fieldSupplier);
	        fieldSupplier.setBounds(170, 90, 180, 20);

	        labeNit.setText("                         Nit:");
	        add(labeNit);
	        labeNit.setBounds(40, 120, 100, 14);

	        fieldNit.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
					char c = e.getKeyChar();
					if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
					} else {
						String texto = String.valueOf(c);
						e.consume();
						fieldNit.setText(fieldNit.getText()
								+ texto.toUpperCase());
					}
				}
			});
	        
	        
	        
	        
	        add(fieldNit);
	        fieldNit.setBounds(170, 120, 180, 20);
	        
	        
	        buttonSave.setText("Guardar");
	        add(buttonSave);
	        buttonSave.setBounds(270, 220, 80, 23);
	        
	        

	        buttonSave.addActionListener(new java.awt.event.ActionListener() 
	        {
	            public void actionPerformed(java.awt.event.ActionEvent evt) 
	            {	
	            	try
	            	{
	            		administrator.saveSupplier(fieldSupplier.getText(), fieldNit.getText());
	            	}
	            	catch(Exception e)
	            	{
	            		JOptionPane.showMessageDialog(null, "Falta un dato","Error",JOptionPane.ERROR_MESSAGE);
	            	}
	            	
	            	
	            	
	            
	            }
	        });

	        setLocation(230, 60);
			setSize(400, 500);
	        
	    }

	    
		public void cleanFields()
		{
			fieldNit.setText("");
			fieldSupplier.setText("");
			
			
		}
	    
		public void setAdministrator(CAdministrator administrator) {
			this.administrator = administrator;
		}

}
